<?php
	session_start();
	var_dump($_SESSION);
	echo '<br/>';
	var_dump($_GET);
	
	//默认现在是第一页
	$nowPage = isset($_GET['page']) ? $_GET['page'] : 1;
	//一页有几行
	$count = 4;
	//当前页面从哪开始
	$start = ($nowPage - 1)*$count;
	//判断可不可以有上一页
	if($nowPage > 1){
		$prevPage = $nowPage - 1;
	}else{
		$prevPage = 1;
	}
	
	//链接数据库
	$con = mysqli_connect('localhost','root','www');
	mysqli_set_charset($con,'utf8');
	mysqli_select_db($con,'admin');
	//判断是否可以下一页
	$countSQL = "select count(*) as shuliang from reply where pid={$_GET['pid']}";
	//执行countSQL 语句
	$resu = mysqli_query($con,$countSQL);
	$shuliang = mysqli_fetch_assoc($resu)['shuliang'];
	//echo $shuliang;
	//计算总页数
	$pages = ceil($shuliang / $count);
	if($nowPage < $pages){
		$nextPage = $nowPage + 1;
	}else{
		$nextPage = $pages;
	}
	
	
?>

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<title>兄弟连论坛-兄弟连Linux基础知识与系统管理视频教程下载地址</title>
	<link href="../public/home/css/qingkongsuoyougeshi.css" rel="stylesheet" style="text/css" />
	<link href="../public/home/css/css6.css" rel="stylesheet" style="text/css" />
</head>
<body>
	<div id="top">
		<div id="top1">
			<div>
				<div>
					<div id="top1a">
						<a href="#">设为首页</a>
						<a href="#">收藏LAMP兄弟连 </a>
						<a href="#">帮助</a>
						<a href="#">推广链接</a>
						<a href="#">社区应用</a>
						<a href="#">最新帖子</a>
						<a href="#">精华区</a>
						<a href="#">社区服务</a>
						<a href="#">会员列表</a>
						<a href="#">统计排行</a>
						<a href="#">搜索</a>
					</div>
				</div>
			</div>
		</div>
		<div id="top2">
			<div>
				<div id="img">
					<img src="../public/home/img/logo.png" />
				</div>
			
				<?php
					if(!isset($_SESSION['uid'])){
				?>
				
				<div>
					<div id="denglu">
						<form method="post" action="doLogin.php">
							<input type="text" name="userName" />
							<input type="password" name="password" />
							<input type="checkbox" name="checkbox" value="jizhu" />
							<span>记住密码</span>
							<a href="#">找回密码</a>
							<input type="submit" name="deng" value="登录" />
							<button type="submit">注册</button>
						</form>
					</div>
				</div>
				<?php
					}else{
					$auths = array('普通用户','管理员');
				?>
					
					<div id='php'>
						<div id='php1'>
							<div><p>会员名：hehhe &nbsp;.</p></div>				
							<div><p>[<?php echo $auths[$_SESSION['auth']] ?>]</p></div>
							<div><p>[积分:50]</p></div>
						</div>
						<div id='php2'>
							<div><img src="../public/home/tmp_name/<?php echo $_SESSION['photo']; ?>" /></div>
						</div>
						<div id='php3'>
							<!--<a href='./updateNames.php'>更改个人信息</a>
							<a href='./updateHeadPhoto.php?id=<?php echo $_GET['id']; ?>'>更改头像</a>-->
						</div>
						<div id='php4'>
							<a href='./out.php'>退出</a>
						</div>
						<div style='clear:both'></div>
					</div>
				<?php
					}
				?>
			</div>
		</div>
		<div id="top3">
			<div>
				<div>
					<a href="#">技术交流</a>
					<a href="#">兄弟连</a>
					<a href="#">连队趣事</a>
					<a href="#">议事厅</a>
				</div>
			</div>
		</div>
	</div>
	<div id="zhongxia">
		<div id=zhong1>
			<div>
				<div>
					<a href='./postList.php?tid=<?php echo $_GET['tid']; ?>&id=<?php echo $_GET['id']; ?>'><img src="../public/home/img/home.gif.png"></a>
					<span>LAMP > PHP技术交流 > 回复帖子</span>
				</div>
				<div>
					<div>
						<a href="./reply.php?tid=<?php echo $_GET['tid']; ?>&pid=<?php echo $_GET['pid']; ?>&page=1">首页</a>
					</div>	
					<div>	
						<a href="./reply.php?tid=<?php echo $_GET['tid']; ?>&pid=<?php echo $_GET['pid']; ?>&page=<?php echo $prevPage; ?>">上一页</a>
					</div>	
					<div>	
						<a href="./reply.php?tid=<?php echo $_GET['tid']; ?>&pid=<?php echo $_GET['pid']; ?>&page=<?php echo $nextPage; ?>">下一页</a>
					</div>	
					<div>	
						<a href="./reply.php?tid=<?php echo $_GET['tid']; ?>&pid=<?php echo $_GET['pid']; ?>&page=<?php echo $pages; ?>">尾页</a>
					</div>
					
					<div>
						<a href='./postList.php?tid=<?php echo $_GET['tid']; ?>&id=<?php echo $_GET['id']; ?>&pid=<?php echo $_GET['pid']; ?>'>发帖</a>
					</div>
					<div>
						
						<a href='./huifu.php?id=<?php echo $_GET['id']; ?>&pid=<?php echo $_GET['pid']; ?>&tid=<?php echo $_GET['tid']; ?>'>回复</a>
						
					</div>
					
					
					<!--<form method="post" action="xo.php" id="anniu">
						<input type="submit" name="reply" value="回复" />
						<input type="button" name="fa" value="发帖" />
					</form>-->
					
					<div style="clear:both"></div>
				</div>
				
				<div>
					<div id="read">
						<span>251696</span>
						<span>阅读</span>
					</div>
					<div id="huifu">
						<span>275</span>
						<span>回复</span>
					</div>
					<div id="Linux">
						<span>兄弟连Linux基础知识与系统管理视频教程下载地址</span>
					</div>
				</div>
				
				
				<div id="biao">
					<?php
						//连接数据库
						$con = mysqli_connect('localhost','root','www');
						mysqli_set_charset($con,'utf8');
						mysqli_select_db($con,'admin');
						//准备SQL语句 查找主题内容
						$SQL = "select * from post where tid={$_GET['tid']} and id={$_GET['pid']}";
						$result = mysqli_query($con,$SQL);
						
						while($arr = mysqli_fetch_assoc($result)){
						
						//准备SQL语句，查找发帖人的昵称 头像
						$SQL2 = "select user.auth,userDetail.name,userDetail.photo from user,userDetail where user.id={$arr['uid']} and userDetail.id={$arr['uid']}";
						$result2 = mysqli_query($con,$SQL2);
						$arr2 = mysqli_fetch_assoc($result2);
						$auths = array('普通用户','管理员');
						
					?>
				
					<div>
						<div>
							<span>楼主:【<?php echo $arr2['name']; ?>】</span>
							<div>
								<img src="../public/home/img/<?php echo $arr2['photo']; ?>" />
							</div>
							<span>(<?php echo $auths[$arr2['auth']]; ?>)</span>
						</div>
						<div>
							<div>
								<span>楼主</span>
								<span>发表于:<?php echo date('Y-m-d H:i:s',$arr['ctime']); ?></span>
							</div>
							<div>
								<span><?php echo $arr['content']; ?></span>
							</div>
						</div>
					</div>
					<?php
						}
					?>
				</div>
				<?php
					//准备SQL语句，查找出回帖内容
					$SQL3 = "select * from reply where pid={$_GET['pid']} limit {$start},{$count}";
					$result3 = mysqli_query($con,$SQL3);
					$a= 1;
					while($arr3 = mysqli_fetch_assoc($result3)){
						//准备SQL语句用reply表中的uid 查找回帖人的信息
						$SQL4 = "select user.auth,userDetail.name,userDetail.photo from user,userDetail where user.id={$arr3['uid']} and userDetail.id={$arr3['uid']}";
						$result4 = mysqli_query($con,$SQL4);
						$arr4 = mysqli_fetch_assoc($result4);
						$auths = array('普通用户','管理员');
						$ceng = array(1=>'沙发','地板','板凳','下水道','臭水沟');
				?>
				<div id="biao">
					<div>
						<div>
							<span>层主:【<?php echo $arr4['name']; ?>】</span>
							<div>
								<img src="../public/home/img/<?php echo $arr4['photo']; ?>" />
							</div>
							<span>(<?php echo $auths[$arr4['auth']]; ?>)</span>
						</div>
						<div>
							<div>
							<?php
								if($a < 6){
							?>
								<span><?php echo $ceng[$a]; ?>.</span>
							<?php
								}else{
							?>	
								<span><?php echo $a; ?>楼.</span>
							<?php
								}
							?>	
								
								<span>发表于:<?php echo date('Y-m-d H:i:s',$arr3['ctime']) ?></span>
								
							</div>
							<div>
								<span><?php echo $arr3['content']; ?></span>
							</div>
						</div>
					</div>
				</div>
				<?php
					$a++;
					}
				?>
				
				
				
				<!--<div id="biao">
					<div>
						<div>
							<span>李明</span>
							<div>
								<img src="../img/2426.jpg" />
							</div>
							<span>司令(管理员)</span>
						</div>
						<div>
							<div>
								<span>板凳</span>
								<span>发表于:05-20</span>
							</div>
							<div>
								<span>不错。。。。。。。。。。</span>
							</div>
						</div>
					</div>
				</div>
				
				
				<div id="biao">
					<div>
						<div>
							<span>李明</span>
							<div>
								<img src="../img/2426.jpg" />
							</div>
							<span>司令(管理员)</span>
						</div>
						<div>
							<div>
								<span>地板</span>
								<span>发表于:05-20</span>
							</div>
							<div>
								<span>不错。。。。。。。。。。</span>
							</div>
						</div>
					</div>
				</div>
				
				
				<div id="biao">
					<div>
						<div>
							<span>李明</span>
							<div>
								<img src="../img/2426.jpg" />
							</div>
							<span>司令(管理员)</span>
						</div>
						<div>
							<div>
								<span>4楼</span>
								<span>发表于:05-20</span>
							</div>
							<div>
								<span>不错。。。。。。。。。。</span>
							</div>
						</div>
					</div>
				</div>-->
				
				
					
				<div id='lianjie'>
					<div>
						<a href="./reply.php?tid=<?php echo $_GET['tid']; ?>&pid=<?php echo $_GET['pid']; ?>&page=1">首页</a>
					</div>	
					<div>	
						<a href="./reply.php?tid=<?php echo $_GET['tid']; ?>&pid=<?php echo $_GET['pid']; ?>&page=<?php echo $prevPage; ?>">上一页</a>
					</div>	
					<div>	
						<a href="./reply.php?tid=<?php echo $_GET['tid']; ?>&pid=<?php echo $_GET['pid']; ?>&page=<?php echo $nextPage; ?>">下一页</a>
					</div>	
					<div>	
						<a href="./reply.php?tid=<?php echo $_GET['tid']; ?>&pid=<?php echo $_GET['pid']; ?>&page=<?php echo $pages; ?>">尾页</a>
					</div>
						<!--<form method="post" action="xo.php" id="anniu">
							<input type="submit" name="reply" value="回复" />
							<input type="button" name="fa" value="发帖" />
						</form>-->
				</div>
				
				
				<div id="dibu">
					<div id="alianjie">
						<a href="#">联系我们</a>
						<span>|</sapn>
						<a href="#">无图版</a>
						<span>|</span>
						<a href="#">手机浏览</a>
						<span>|</span>
						<a href="#">清除COOKIES</a>
					</div>
					<div id="dibuwenzi">
						<p>Powered by phpwind v8.7 Certificate Copytight Time now is:08-22 08:45</p>
					</div>
					<div id="gongbeihao">
						<p>?2006-2015 LAMP兄弟连 版权所有 Gzip disabled 京ICP备11018177号 Total 0.040525(s) query 3,京公网安备11011302000117</p>
					</div>
				</div>
				
				
			
			</div>
		</div>
	</div>
</body>
</html>